<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div class="search" v-show="showSearch">
        <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
          <el-form-item label="用户昵称" prop="nickName">
            <el-input v-model="queryParams.nickName" placeholder="请输入用户昵称" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="是否代理" prop="isProxy">
            <el-select v-model="queryParams.isProxy" placeholder="请选择是否代理" clearable>
              <el-option
                v-for="dict in is_proxy"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="手机号码" prop="phonenumber">
            <el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </transition>

    <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户ID" align="center" prop="userId" v-if="true" width="200px" show-overflow-tooltip />
      <el-table-column label="用户昵称" align="center" prop="nickName" width="200px" show-overflow-tooltip/>
      <el-table-column label="手机号" align="center" prop="phonenumber" width="150px" show-overflow-tooltip/>
      <!--        <el-table-column label="姓名" align="center" prop="name" />-->
      <el-table-column label="审核状态" align="center" prop="ifCardReview" width="100px" show-overflow-tooltip>
        <template #default="scope">
          <dict-tag :options="yhshzt" :value="scope.row.ifCardReview"/>
        </template>
      </el-table-column>
      <el-table-column label="用户类型" align="center" prop="type" width="100px" show-overflow-tooltip>
        <template #default="scope">
          <dict-tag :options="user_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="vip等级" align="center" prop="vip" :formatter="formatVip" width="100px" show-overflow-tooltip />
      <el-table-column label="代理区域" align="center" prop="proxyRegion" width="100px" show-overflow-tooltip />
      <el-table-column label="审核理由" align="center" prop="reasonsReview" width="200px" show-overflow-tooltip/>
      <el-table-column label="是不是代理" align="center" prop="isProxy" width="100px" show-overflow-tooltip>
        <template #default="scope">
          <dict-tag :options="is_proxy" :value="scope.row.isProxy"/>
        </template>
      </el-table-column>
      <el-table-column label="代理审核状态" align="center" prop="proxyApprovalStatus" width="200px" show-overflow-tooltip>
        <template #default="scope">
          <dict-tag :options="approval_status" :value="scope.row.proxyApprovalStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="代理审核备注" align="center" prop="proxyRemarks" width="200px" show-overflow-tooltip/>
      <el-table-column label="会员次数" align="center" prop="hyNumber" width="100px" show-overflow-tooltip/>
      <el-table-column label="会员充值时间" align="center" prop="vipTime" width="200px" show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="会员过期时间" align="center" prop="gqTime" width="200px" show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="代理过期时间" align="center" prop="approvalTime" width="200px" show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="联系方式" align="center" prop="enterprisePhone" width="150px" show-overflow-tooltip/>
      <el-table-column label="操作" align="center" width="180" fixed="right">
        <template #default="scope">
          <el-tooltip content="修改" placement="top">
            <el-button link type="primary" icon="View" @click="handleUpdate(scope.row)" v-hasPermi="['system:user:edit']"></el-button>
          </el-tooltip>
          <el-tooltip content="删除" placement="top">
            <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:user:remove']"></el-button>
          </el-tooltip>
          <el-tooltip content="审核" placement="top">
            <el-button link type="primary" v-if="scope.row.ifCardReview==2 ||scope.row.ifCardReview==4" icon="Edit" @click="handleExamine(scope.row)" v-hasPermi="['system:user:edit']"></el-button>
          </el-tooltip>
          <el-tooltip content="代理审核" placement="top">
            <el-button link type="primary" v-if="scope.row.proxyApprovalStatus==2 ||scope.row.proxyApprovalStatus==4" icon="Edit" @click="handleProxyReview(scope.row)" v-hasPermi="['system:user:edit']"></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <!--    </el-card>-->
    <!-- 添加或修改用户信息对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="600px" append-to-body>
      <el-form ref="userFormRef" :model="form" :rules="rules"  label-position="top" label-width="120px">
        <!--        <el-form-item label="部门ID" prop="deptId">
                  <el-input v-model="form.deptId" placeholder="请输入部门ID" />
                </el-form-item>
                <el-form-item label="用户账号" prop="userName">
                  <el-input v-model="form.userName" placeholder="请输入用户账号" />
                </el-form-item>-->
        <el-form-item label="用户昵称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入用户昵称" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phonenumber">
          <el-input v-model="form.phonenumber" placeholder="请输入手机号码" />
        </el-form-item>
        <!--        <el-form-item label="用户邮箱" prop="email">
                  <el-input v-model="form.email" placeholder="请输入用户邮箱" />
                </el-form-item>
                <el-form-item label="手机号码" prop="phonenumber">
                  <el-input v-model="form.phonenumber" placeholder="请输入手机号码" />
                </el-form-item>
                <el-form-item label="openid" prop="openid">
                  <el-input v-model="form.openid" placeholder="请输入openid" />
                </el-form-item>
                <el-form-item label="unionid" prop="unionid">
                  <el-input v-model="form.unionid" placeholder="请输入unionid" />
                </el-form-item>
                <el-form-item label="头像地址" prop="avatar">
                  <el-input v-model="form.avatar" placeholder="请输入头像地址" />
                </el-form-item>
                <el-form-item label="密码" prop="password">
                  <el-input v-model="form.password" placeholder="请输入密码" />
                </el-form-item>
                <el-form-item label="积分" prop="amount">
                  <el-input v-model="form.amount" placeholder="请输入积分" />
                </el-form-item>
                <el-form-item label="总花费金额 用于用户vip等级评定" prop="allAmount">
                  <el-input v-model="form.allAmount" placeholder="请输入总花费金额 用于用户vip等级评定" />
                </el-form-item>
                <el-form-item label="最后登录IP" prop="loginIp">
                  <el-input v-model="form.loginIp" placeholder="请输入最后登录IP" />
                </el-form-item>
                <el-form-item label="最后登录时间" prop="loginDate">
                  <el-date-picker clearable
                    v-model="form.loginDate"
                    type="datetime"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    placeholder="请选择最后登录时间">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item label="二维码" prop="qrCode">
                  <el-input v-model="form.qrCode" placeholder="请输入二维码" />
                </el-form-item>
                <el-form-item label="上级" prop="superiorId">
                  <el-input v-model="form.superiorId" placeholder="请输入上级" />
                </el-form-item>
                <el-form-item label="微信头像地址" prop="wxAvatar">
                  <el-input v-model="form.wxAvatar" placeholder="请输入微信头像地址" />
                </el-form-item>-->
        <el-form-item label="审核" prop="ifCardReview">
          <el-radio-group v-model="form.ifCardReview">
            <el-radio
              v-for="dict in yhshzt"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核理由" prop="reasonsReview">
          <el-input v-model="form.reasonsReview" placeholder="请输入审核理由" />
        </el-form-item>
        <!--        <el-form-item label="" prop="idCardId">
                  <el-input v-model="form.idCardId" placeholder="请输入" />
                </el-form-item>
                <el-form-item label="" prop="idCardNegativeId">
                  <el-input v-model="form.idCardNegativeId" placeholder="请输入" />
                </el-form-item>
                <el-form-item label="身份证姓名" prop="sfzXm">
                  <el-input v-model="form.sfzXm" placeholder="请输入身份证姓名" />
                </el-form-item>
                <el-form-item label="身份证号码" prop="sfzHm">
                  <el-input v-model="form.sfzHm" placeholder="请输入身份证号码" />
                </el-form-item>
                <el-form-item label="手持身份证正面" prop="idCardIdSczm">
                  <el-input v-model="form.idCardIdSczm" placeholder="请输入手持身份证正面" />
                </el-form-item>-->
        <el-form-item label="会员次数" prop="hyNumber">
          <el-input v-model="form.hyNumber" placeholder="请输入会员次数" />
        </el-form-item>
        <el-form-item label="积分" prop="points">
          <el-input v-model="form.points" placeholder="请输入会员次数" />
        </el-form-item>
        <el-form-item label="会员过期时间" prop="gqTime">
          <el-date-picker clearable
                          v-model="form.gqTime"
                          type="datetime"
                          value-format="YYYY-MM-DD HH:mm:ss"
                          placeholder="请选择会员过期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="代理过期时间" prop="approvalTime">
          <el-date-picker clearable
                          v-model="form.approvalTime"
                          type="datetime"
                          value-format="YYYY-MM-DD HH:mm:ss"
                          placeholder="请选择代理过期时间">
          </el-date-picker>
        </el-form-item>
        <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">身份：{{form.typeName}}</div>
        <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">地区：{{form.city}}</div>
        <div v-if="form.type==1">
          <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">姓名：{{form.sfzXm}}</div>
          <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">身份证号码：{{form.sfzHm}}</div>
          <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">身份证人像面</div>
          <ImagePreview  :height="150" :src="form.idCardUrl"
                        :preview-src-list="form.idCardUrl?.split(',')"/>
          <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">身份证国徽面</div>
          <ImagePreview :height="150" :src="form.idCardNegativeUrl"
                        :preview-src-list="form.idCardNegativeUrl?.split(',')"/>
        </div>
        <div v-else>
          <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">企业名称：{{form.enterpriseName}}</div>
          <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">联系方式：{{form.enterprisePhone}}</div>
          <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">营业执照</div>
          <ImagePreview :height="150" :src="form.businessLicenseUrl"
                        :preview-src-list="form.businessLicenseUrl?.split(',')"/>
        </div>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog v-model="isExamineShow" title="实名审核" width="30%" top="5vh" append-to-body>
      <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">身份：{{infoData.typeName}}</div>
      <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">地区：{{infoData.city}}</div>
      <div v-if="infoData.type==1">
        <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">姓名：{{infoData.sfzXm}}</div>
        <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">身份证号码：{{infoDatasfzHm}}</div>
        <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">身份证人像面</div>
        <ImagePreview  :height="150" :src="infoData.idCardUrl"
                       :preview-src-list="infoData.idCardUrl?.split(',')"/>
        <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">身份证国徽面</div>
        <ImagePreview :height="150" :src="infoData.idCardNegativeUrl"
                      :preview-src-list="infoData.idCardNegativeUrl?.split(',')"/>
      </div>
      <div v-else>
        <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">企业名称：{{infoData.enterpriseName}}</div>
        <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">联系方式：{{infoData.enterprisePhone}}</div>
        <div style="margin-top: 10px;margin-bottom: 5px;font-size: 16px">营业执照</div>
        <ImagePreview :height="150" :src="infoData.businessLicenseUrl"
                      :preview-src-list="infoData.businessLicenseUrl?.split(',')"/>
      </div>
      <el-divider />
      <div>
        <el-radio-group v-model="ifCardReview" @change="handleExamineChange">
          <el-radio :value="'3'">通过</el-radio>
          <el-radio :value="'4'">驳回</el-radio>
        </el-radio-group>
      </div>
      <div>
        <el-input v-if="ifCardReview==4" v-model="reasonsReview" :autosize="{ minRows: 4, maxRows: 6 }" type="textarea" placeholder="请输入驳回原因" />
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="isExamineShow = false">取消</el-button>
          <el-button type="primary" @click="handleExamineSumbit">  确定 </el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog v-model="proxyRevieweShow" title="代理审核" width="30%" top="5vh" append-to-body>

      <el-form-item label="姓名" prop="name">
        <el-input v-model="name" placeholder="请输入姓名" disabled  />
      </el-form-item>

      <el-form-item label="手机号码" prop="phonenumber">
        <el-input v-model="phonenumber" placeholder="请输入手机号码" disabled  />
      </el-form-item>
      <el-form-item label="代理区域" prop="proxyRegion">
        <el-input v-model="proxyRegion" placeholder="请输入会员次数"   disabled />
      </el-form-item>

      <el-form-item label="用户所在城市" prop="city">
        <el-input v-model="city" placeholder="请输入会员次数" disabled  />
      </el-form-item>
      <el-divider />
      <div>
        <el-radio-group v-model="proxyApprovalStatus" @change="handleExamineChange">
          <el-radio :value="'3'">通过</el-radio>
          <el-radio :value="'4'">驳回</el-radio>
        </el-radio-group>
      </div>
      <div>
        <el-input v-if="proxyApprovalStatus==4" v-model="proxyRemarks" :autosize="{ minRows: 4, maxRows: 6 }" type="textarea" placeholder="请输入驳回原因" />
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="proxyRevieweShow = false">取消</el-button>
          <el-button type="primary" @click="auditButton">  确定 </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="User" lang="ts">
import { listUser, getUser, delUser, addUser, updateUser } from '@/api/business/user';
import { UserVO, UserQuery, UserForm } from '@/api/business/user/types';
import {getByKeyApi} from '@/api/business/config';
import {BusinessUserVO} from '@/api/business/businessUser/types';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { yhshzt } = toRefs<any>(proxy?.useDict('yhshzt'));
const { user_type } = toRefs<any>(proxy?.useDict('user_type'));
const { approval_status } = toRefs<any>(proxy?.useDict('approval_status'));
const { is_proxy } = toRefs<any>(proxy?.useDict('is_proxy'));


const userList = ref<UserVO[]>([]);
const buttonLoading = ref(false);
const vipList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const userFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const initFormData: UserForm = {
  userId: undefined,
  deptId: undefined,
  userName: undefined,
  nickName: undefined,
  userType: undefined,
  email: undefined,
  phonenumber: undefined,
  openid: undefined,
  unionid: undefined,
  sex: undefined,
  avatar: undefined,
  password: undefined,
  amount: undefined,
  allAmount: undefined,
  status: undefined,
  loginIp: undefined,
  loginDate: undefined,
  remark: undefined,
  qrCode: undefined,
  superiorId: undefined,
  wxAvatar: undefined,
  ifCardReview: undefined,
  reasonsReview: undefined,
  idCardId: undefined,
  idCardNegativeId: undefined,
  sfzXm: undefined,
  sfzHm: undefined,
  idCardIdSczm: undefined,
  hyNumber: undefined,
  isProxy: undefined,
  gqTime: undefined
}
const data = reactive<PageData<UserForm, UserQuery>>({
  form: {...initFormData},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    deptId: undefined,
    userName: undefined,
    nickName: undefined,
    userType: undefined,
    email: undefined,
    phonenumber: undefined,
    openid: undefined,
    unionid: undefined,
    sex: undefined,
    avatar: undefined,
    password: undefined,
    amount: undefined,
    allAmount: undefined,
    status: undefined,
    loginIp: undefined,
    loginDate: undefined,
    qrCode: undefined,
    superiorId: undefined,
    wxAvatar: undefined,
    ifCardReview: undefined,
    reasonsReview: undefined,
    idCardId: undefined,
    idCardNegativeId: undefined,
    sfzXm: undefined,
    sfzHm: undefined,
    idCardIdSczm: undefined,
    hyNumber: undefined,
    isProxy: undefined,
    gqTime: undefined,
    params: {
    }
  },
  rules: {
    userId: [
      { required: true, message: "用户ID不能为空", trigger: "blur" }
    ],
    deptId: [
      { required: true, message: "部门ID不能为空", trigger: "blur" }
    ],
    userName: [
      { required: true, message: "用户账号不能为空", trigger: "blur" }
    ],
    nickName: [
      { required: true, message: "用户昵称不能为空", trigger: "blur" }
    ],
    userType: [
      { required: true, message: "用户类型不能为空", trigger: "change" }
    ],
    email: [
      { required: true, message: "用户邮箱不能为空", trigger: "blur" }
    ],
    phonenumber: [
      { required: true, message: "手机号码不能为空", trigger: "blur" }
    ],
    openid: [
      { required: true, message: "openid不能为空", trigger: "blur" }
    ],
    unionid: [
      { required: true, message: "unionid不能为空", trigger: "blur" }
    ],
    sex: [
      { required: true, message: "用户性别不能为空", trigger: "change" }
    ],
    avatar: [
      { required: true, message: "头像地址不能为空", trigger: "blur" }
    ],
    password: [
      { required: true, message: "密码不能为空", trigger: "blur" }
    ],
    amount: [
      { required: true, message: "积分不能为空", trigger: "blur" }
    ],
    allAmount: [
      { required: true, message: "总花费金额 用于用户vip等级评定不能为空", trigger: "blur" }
    ],
    status: [
      { required: true, message: "帐号状态不能为空", trigger: "change" }
    ],
    loginIp: [
      { required: true, message: "最后登录IP不能为空", trigger: "blur" }
    ],
    loginDate: [
      { required: true, message: "最后登录时间不能为空", trigger: "blur" }
    ],
    remark: [
      { required: true, message: "备注不能为空", trigger: "blur" }
    ],
    qrCode: [
      { required: true, message: "二维码不能为空", trigger: "blur" }
    ],
    superiorId: [
      { required: true, message: "上级不能为空", trigger: "blur" }
    ],
    wxAvatar: [
      { required: true, message: "微信头像地址不能为空", trigger: "blur" }
    ],
    ifCardReview: [
      { required: true, message: "0未审核 1待审核 2审核通过 3审核未通过不能为空", trigger: "change" }
    ],
    reasonsReview: [
      { required: true, message: "审核理由不能为空", trigger: "blur" }
    ],
    proxyRemarks: [
      { required: true, message: "代理审核理由不能为空", trigger: "blur" }
    ],
    idCardId: [
      { required: true, message: "不能为空", trigger: "blur" }
    ],
    idCardNegativeId: [
      { required: true, message: "不能为空", trigger: "blur" }
    ],
    sfzXm: [
      { required: true, message: "身份证姓名不能为空", trigger: "blur" }
    ],
    sfzHm: [
      { required: true, message: "身份证号码不能为空", trigger: "blur" }
    ],
    idCardIdSczm: [
      { required: true, message: "手持身份证正面不能为空", trigger: "blur" }
    ],
    hyNumber: [
      { required: true, message: "会员次数不能为空", trigger: "blur" }
    ],
    gqTime: [
      { required: true, message: "会员过期时间不能为空", trigger: "blur" }
    ]
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询用户信息列表 */
const getList = async () => {
  loading.value = true;
  const res = await listUser(queryParams.value);
  userList.value = res.rows;
  total.value = res.total;
  loading.value = false;
}

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
}
const getByKey = async () => {
  const res = await getByKeyApi('vip');
  vipList.value = res.data;
};
const formatVip = (row: BusinessUserVO, column: any) => {
  return vipList.value.find((item: any) => item.sortNo == row.vip)?.configName;
};
/** 表单重置 */
const reset = () => {
  form.value = {...initFormData};
  userFormRef.value?.resetFields();
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
}

/** 多选框选中数据 */
const handleSelectionChange = (selection: UserVO[]) => {
  ids.value = selection.map(item => item.userId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = "添加用户信息";
}

/** 修改按钮操作 */
const handleUpdate = async (row?: UserVO) => {
  reset();
  const _userId = row?.userId || ids.value[0]
  const res = await getUser(_userId);
  Object.assign(form.value, res.data);
  dialog.visible = true;
  dialog.title = "修改用户信息";
}

/** 提交按钮 */
const submitForm = () => {
  userFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.userId) {
        await updateUser(form.value).finally(() =>  buttonLoading.value = false);
      } else {
        await addUser(form.value).finally(() =>  buttonLoading.value = false);
      }
      proxy?.$modal.msgSuccess("修改成功");
      dialog.visible = false;
      await getList();
    }
  });
}

/** 删除按钮操作 */
const handleDelete = async (row?: UserVO) => {
  const _userIds = row?.userId || ids.value;
  await proxy?.$modal.confirm('是否确认删除用户信息编号为"' + _userIds + '"的数据项？').finally(() => loading.value = false);
  await delUser(_userIds);
  proxy?.$modal.msgSuccess("删除成功");
  await getList();
}

/** 审核 */
const userId = ref('')
const isExamineShow = ref(false);
const idCardNegative = ref('');
const idCard = ref('');
const idCardIdSczm = ref('');
const ifCardReview = ref('');
const reasonsReview = ref('');
const infoData = ref();
const handleExamine = async (row?: BusinessUserVO) => {
  infoData.value=row
    idCardNegative.value = row?.idCardNegativeUrl
    idCard.value = row?.idCardUrl
    idCardIdSczm.value = row?.idCardIdSczmUrl
    userId.value = row?.userId
  isExamineShow.value=true
}
/**
 * 代理审核
 * @param row
 */
const city = ref('');
const name = ref('');
const phonenumber = ref('');
const proxyRemarks = ref('');
const proxyApprovalStatus = ref('');
const proxyRegion = ref('');
const proxyRevieweShow = ref(false);

const handleProxyReview = async (row?: BusinessUserVO) => {
  city.value = row?.city
  name.value = row?.name
  phonenumber.value = row?.phonenumber
  proxyRemarks.value = row?.proxyRemarks
  proxyApprovalStatus.value = row?.proxyApprovalStatus
  proxyRegion.value = row?.proxyRegion
  userId.value = row?.userId
  proxyRevieweShow.value=true
}
const handleExamineChange = (e) => {
  console.log("e", e);
}
const handleExamineSumbit = async () => {
  if (!ifCardReview.value){
    proxy?.$modal.msgWarning("请选择是否通过审核");
    return
  }else{
    if (ifCardReview.value==4&&!reasonsReview.value){
      proxy?.$modal.msgWarning("请输入不通过原因");
      return
    }
  }
  verifyIdentityApproval ({ifCardReview:ifCardReview.value,reasonsReview:reasonsReview.value,userId:userId.value}).then(res=>{
    proxy?.$modal.msgSuccess(res.msg);
    if (res.code==200){
      isExamineShow.value=false
      reasonsReview.value=''
      getList()
    }
  })
}
/**
 * 代理审核
 */
const auditButton = async () => {
  if (!proxyApprovalStatus.value){
    proxy?.$modal.msgWarning("请选择是否通过审核");
    return
  }else{
    if (proxyApprovalStatus.value==4&&!proxyRemarks.value){
      proxy?.$modal.msgWarning("请输入不通过原因");
      return
    }
  }
  proxyApproval({proxyApprovalStatus:proxyApprovalStatus.value,proxyRemarks:proxyRemarks.value,userId:userId.value}).then(res=>{
    proxy?.$modal.msgSuccess(res.msg);
    if (res.code==200){
      proxyRevieweShow.value=false
      proxyApprovalStatus.value=''
      getList()
    }
  })
}
/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download('system/user/export', {
    ...queryParams.value
  }, `user_${new Date().getTime()}.xlsx`)
}
const handleShowImg = (img) => {
  window.open(img)
}

onMounted(() => {
  getList();
  getByKey();
});
</script>
